All right.
So in this lecture we're going to be creating the basic loading screen for our lobby.
This loading screen will wait until the first screenshot of the game has been replicated to the client.
And then it's also going to wait until all the scripts have been initialized on the client and on the
server.
Once everything has finished loading, then we're going to fade out the loading screen.
So let's go ahead and take a look at what our loading screen looks like.
So I'm going to copy this intro menu here or our loading screen.
I'm going to put it inside of starter Guy and let me go ahead and enable UI visibility.
So we're going to have this screen on here.
It's going to give us a warning.
You know this is a game with jumpscares flashing lights stuff like that.
And then then we're also going to have uh, another little text down here that's going to tell us what
we're loading.
So it'll say loading or loading client or waiting on server and stuff like that.
And of course we have our warning label and we have our warning text.
So to get started, let's go ahead and open up our loading guy handler script.
And inside of here we're going to need access to two services.
One is going to be the player service.
So we can get a reference to the local player.
And then we're also going to get access to the tween service.
That way we can fade out this guy when we're done loading the game.
I'm going to have a variable to reference a clone of our guy.
So we're going to call it clone guy.
And it's going to be equal to the script.
And we're going to get the child, which is the intro menu.
And we're going to clone this guy.
And then we're going to set the parent of this clone guy equal to the players dot local player, dot
player guy folder.
And then at the same time we're going to reference replicated first by doing script dot parent.
And there's a function in there called remove default loading screen.
So this will allow us to see our uh loading guy much faster.
And we're removing the default Roblox loading screen.
After that, we can also create a reference to the text label that is inside of our clone guy.
So clone guy get the frame and then get the loading text.
And then here I'm going to create some constants for the loading text.
So we're going to have our standard loading text which will just say loading.
We'll have some texts for waiting for the server.
So we'll call it wait for server.
And then we'll have some text for waiting on the client.
So wait for client is equal to waiting for client.
All right.
Now, in this section, what I want to do is I want to use the task spawn function to spawn a function
in a new thread.
And what we're going to do is we're going to set the text labels text equal to the loading text.
And then we're going to wait for 0.6 seconds.
And then we're going to create a while loop.
So what this while loop is going to check is whether or not the game is loaded.
So while not game is loaded we're going to loop.
So what we're going to do is we're going to set the text label dot text equal to uh itself.
And we're going to concatenate it with a dot.
So we get the, you know, dot dot dot.
When it's loading.
So our UI should look something like this.
Loading.
And then 0.6 seconds it adds a dot and then another dot and then another dot.
And then once it reaches those three dots then it resets it back to that and it continues looping.
So that means I'm going to have to add a check at the beginning here to see if the text label dot text
is equal to the loading text, and concatenate it with three periods.
So if our text is equal to that, then we're going to set the text label dot text back to the loading
text.
And then we're going to wait for 0.6 seconds.
And then we can wait for 0.6 seconds down here as well.
And that's all we need to do for this while loop.
And the reason I'm spawning it in another thread is because I'm going to put an if statement down here.
So if not game is loaded then we're going to wait for the game to load.
So the next thing I want to check is let's say the workspace get attribute server loaded is nil or false.
So let's say the server hasn't loaded yet.
If the server hasn't loaded then we need to set the text label dot text equal to wait for the server.
And then we can basically just do the exact same thing here as well.
But instead we're just going to copy all this text and replace it from our loading text.
And then I'm going to basically do the exact same thing down here again.
But this time we're going to check to see whether or not the client has been loaded.
So if not client loaded then we're going to loop here until that attribute has been changed.
So actually we need to change that here.
As well.
So if.
So while not workspace, get attribute server loaded.
And then down here we're going to do it for the client.
So all not client is loaded.
Then we need to change this text to wait for client.
Copy that and do it here as well.
And then once we have waited for the game to load, we've successfully verified the server is loaded
and then we have successfully verified that the client has loaded.
Then we can go ahead and fade out our loading screen.
So what I'm going to do is I'm going to loop through every single UI element in our UI.
So every single element in Ipairs clone GUI.
And we're just going to get all of the descendants.
And what we're going to do is we're going to check if this element is a frame.
So if it's a frame, then we're going to use the tween service and create a new tween.
On this element.
We could do tween info and fade it out in like 0.5 seconds.
And we want to set the background transparency equal to one.
And then we can just play this tween.
Else.
If this element is, let's say a text label, text label, then instead we need to change the text transparency
and not the background transparency of the text.
So we can just copy this and then change this to the text transparency.
And then once we have loop through all those elements and started tweening them, then we're going to
just wait for 0.5 seconds, which is the duration of the tween.
And then once that's done, we can go ahead and destroy this clone GUI from our UI folder, and then
we can just destroy the script itself as well, because we aren't going to use it anymore.
And that should be our loading guy complete.
So let's go ahead and test it out.
We're going to hit play up here.
And we should see our loading screen.
Or we didn't because apparently the server loaded way too fast.
So let me see if there's a way I could try to slow it down a little bit.
Let me go ahead and go into our start script.
And what I'm going to do is I'm actually going to wait here for like, 10s.
That way we can get the chance to see our loading screen.
So let's try it.
So let's try this again.
There we go.
We are waiting for the client we're currently loading.
And then once the client has loaded everything, then this guy should fade out.
And there we go.
Our joy has faded out because the client has finished loading.
And that's how you can create a basic loading screen for your games.
We're also going to be using this loading screen in the other place for our game.
And we're also going to add a little bit extra feature, where this loading screen will also wait until
all the other players have loaded in the game as well.
Otherwise, see you in the next lecture.